/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.service.impl;

import com.legendshop.dao.support.CriteriaQuery;
import com.legendshop.dao.support.PageSupport;
import com.legendshop.oa.dao.TaskEstimateDao;
import com.legendshop.oa.dto.DailyLogQueryDto;
import com.legendshop.oa.dto.UserOverProjectTimeInputDto;
import com.legendshop.oa.model.TaskEstimate;
import com.legendshop.oa.service.TaskEstimateService;
import com.legendshop.util.AppUtils;

import java.util.Date;
import java.util.List;

/**
 * The Class TaskEstimateServiceImpl. 任务时间估计服务实现类
 */
public class TaskEstimateServiceImpl implements TaskEstimateService {

	/**
	 *
	 * 引用的任务时间估计Dao接口
	 */
	private TaskEstimateDao taskEstimateDao;

	public void setTaskEstimateDao(TaskEstimateDao taskEstimateDao) {
		this.taskEstimateDao = taskEstimateDao;
	}

	/**
	 * 根据商城获取任务时间估计列表
	 */
	public List<TaskEstimate> getTaskEstimate(String userName) {
		return taskEstimateDao.getTaskEstimate(userName);
	}

	/**
	 * 根据Id获取任务时间估计
	 */
	public TaskEstimate getTaskEstimate(Long id) {
		return taskEstimateDao.getTaskEstimate(id);
	}

	/**
	 * 删除任务时间估计
	 */
	public boolean deleteTaskEstimate(TaskEstimate taskEstimate) {
		if(taskEstimate == null) {
			return false;
		}
		if(taskEstimate.getReviewed() == 1) {
			return false;//任务已经评审过,无法删除
		}
		return taskEstimateDao.deleteTaskEstimate(taskEstimate) >0;
	}

	/**
	 * 保存任务时间估计
	 */
	public Long saveTaskEstimate(TaskEstimate taskEstimate) {
		if (!AppUtils.isBlank(taskEstimate.getId())) {
			updateTaskEstimate(taskEstimate);
			return taskEstimate.getId();
		}
		return taskEstimateDao.saveTaskEstimate(taskEstimate);
	}

	/**
	 * 更新任务时间估计
	 */
	public void updateTaskEstimate(TaskEstimate taskEstimate) {
		taskEstimateDao.updateTaskEstimate(taskEstimate);
	}

	/**
	 * 查询任务时间估计列表
	 */
	public PageSupport getTaskEstimate(CriteriaQuery cq) {
		return taskEstimateDao.getTaskEstimate(cq);
	}

	@Override
	public List<TaskEstimate> getTaskEstimateByTask(Long taskId) {
		return taskEstimateDao.getTaskEstimateByTask(taskId);
	}

	@Override
	public List<TaskEstimate> getTaskEstimateByDay(Date date, String userName) {
		return taskEstimateDao.getTaskEstimateByDay(date, userName);
	}

	@Override
	public PageSupport<TaskEstimate> getTaskEstimateByDay(Date startDate, Date endDate, DailyLogQueryDto dailyLogQueryDto) {
		return taskEstimateDao.getTaskEstimateByDay(startDate,endDate, dailyLogQueryDto);
	}

	@Override
	public PageSupport<TaskEstimate> getTaskEstimateByTask(Long taskId, String curPageNO) {
		return taskEstimateDao.getTaskEstimateByTask(taskId, curPageNO);
	}

	@Override
	public PageSupport<TaskEstimate> getTaskEstimateByDay(Date date1, String userName1, String curPageNO) {
		return taskEstimateDao.getTaskEstimateByDay(date1,userName1,curPageNO);
	}

	@Override
	public TaskEstimate getUnReviewedTaskEstimate(Long taskEstimateId) {
		return taskEstimateDao.getUnReviewedTaskEstimate(taskEstimateId);
	}

	@Override
	public Long getTaskEstimateHoursByUser(String userName, Date startDate, Date endDate) {
		return taskEstimateDao.getTaskEstimateHoursByUser(userName, startDate, endDate);
	}
	
	/**
	 *  审核某个用户在一周或者一个月的工时的状态
	 */
	public Integer updateTaskEstimateHoursByUser(String userName, Date startDate, Date endDate) {
		return taskEstimateDao.updateTaskEstimateHoursByUser(userName, startDate, endDate);
	}

	public List<UserOverProjectTimeInputDto> isUserOverProjectTimeInput(String userName, Date startDate, Date endDate){
		return taskEstimateDao.isUserOverProjectTimeInput(userName, startDate, endDate);
	}
	
}
